from collections import namedtuple

from libtcodpy import Color

import backend


class hashabledict(dict):
    def __hash__(self):
        return hash(tuple(sorted(self.items())))


class TestItems(object):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_default_item(self):
        item = backend.Item()
        assert item.__dict__ == {'stats': {}, 'name': 'Unidentified Item', 'weight': 1, 'color': Color(255, 255, 255),
                                 'character': '|', 'skills': {}, 'location': (0, 0), 'misc_stats': {}, 'quantity': 1,
                                 'slots': [None], 'abilities': set()}


class TestFunctions(object):
    Scene = namedtuple('Scene', ['units', 'kill'])
    Unit = namedtuple('Unit', ['stats'])

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_funeral_no_dead(self):
        unit = self.Unit(hashabledict([('strength', 1)]))
        scene = self.Scene({unit}, lambda x: None)
        assert backend.funeral(scene) == False

    def test_funeral_dead(self):
        unit = self.Unit(hashabledict([('strength', 0)]))
        scene = self.Scene({unit}, lambda x: None)
        assert backend.funeral(scene)
